<div class="form">

<?php $form=$this->beginWidget('FActiveForm', array(
	'id'=>'lookup-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

    <?php if (! $model->IsNewRecord) echo $form->hiddenField($model, "id") ; ?>
	<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>128)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'code'); ?>
		<?php echo $form->textField($model,'code'); ?>
		<?php echo $form->error($model,'code'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'type'); ?>
		<?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
                'model' => $model,
                'attribute'=>'type',
                'source'=> 'js:function( request, response ) {
                    $.ajax({
                        url: "'.serviceUrl('Admin.Lookup.searchType').'",
                        dataType: "json",
                        data: {term: request.term.split( /,\s*/ ).pop()},
                        complete: function( obj ) {
                            data = eval(obj.responseText);
                            response( $.map( data.matches, function( item ) {
                                return {
                                    label: item.type,
                                    value: item.type
                                }
                            }));
                        }
                    });
                }',
                'options' => array(
                    'focus' => 'js:function() {
                        // prevent value inserted on focus
                        return false;
                    }',
                    'select' => 'js:function( event, ui ) {
                        var terms = this.value.split( /,\s*/ );
                        // remove the current input
                        terms.pop();
                        // add the selected item
                        terms.push( ui.item.value );
                        // add placeholder to get the comma-and-space at the end
                        //terms.push( "" );
                        this.value = terms;
                        return false;
                    }',
                ),
                'htmlOptions'=>array(
                    'size' => 60,
                	'maxlength'=>128
                )
        ));?>
		<?php echo $form->error($model,'type'); ?>
	</div>
	<?php if(!$model->isNewRecord){?>
	<div class="row">
		<?php echo $form->labelEx($model,'position'); ?>
		<?php echo $form->textField($model,'position'); ?>
		<?php echo $form->error($model,'position'); ?>
	</div>
	<?php }?>
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->